/*******************************************************************************
Last update: September 29, 2025 
********************************************************************************/

/*******************************************************************************
Preliminaries
********************************************************************************/


/******************************************************************************
Figures
******************************************************************************/
cls
clear all
set more off

//Working directory
local wd "D:/Dropbox/Distinction Effect/Replication Package"
*local wd "~/Dropbox/Research/Distinction Effect/Replication Package"
cd "`wd'"

if substr(c(pwd), -19, 19) == "Replication Package" {
	
	//User-written programs used are stored here
	*adopath ++ Does/ado/

	//Load Author-written programs
	local filelist: dir "Does/Analysis/Programs/" files "*.do"
	foreach i of local filelist {
	  qui do "Does/Analysis/Programs/`i'"
	}
}
else {
	break
	dis in red "WARNING: Working directory is not Replication Package"
}

/*******************************************************************************
Globals
********************************************************************************/

//Outcome
global Y ln_earningsMW
//Test Scores
global T reading english sb11score
//Covariates
global X female age stratum meduc_hs meduc_cllg2Y meduc_cllg4Y d_semester2 d_semester3 d_semester4
//Fixed Effects
global FE yarea_*
global FFE yfield_*

//Specification 1
global S1 $FE
//Specification 2
global S2 $T $FE
//Specification 3
global S3 $X $T $FE
	
//Kernel
global kernel "epanechnikov"
	
//SE cluster level
global SE year_area

//Common RDrobust common options
global RDoptions kernel($kernel) all vce(cluster $SE)
global RDoptionsRobust kernel($kernel) all vce(hc3)

//Running Variable
global running score_sd

//Set bandwidth
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009

rdrobust $Y $running, $RDoptions bwselect(mserd) p(1) covs($S3)
global MSE_Bw = e(h_l)
global MSE_Bias = e(b_l)


/*******************************************************************************
Figure 1: Effect of the National Distinction Award on Early-Career Earnings
********************************************************************************/
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009

rdrobust $Y score_sd, all vce(cluster year_area) kernel(epa) bwselect(mserd) p(1) covs(yarea_* $X $T)
global BW = e(h_l)
global PW = e(b_l)

tab award if score_sd >= 1

//Figure 1a
//Aggregate the information after 1
tempvar score
gen double `score' = score_sd
replace `score' = 1 if `score' >= 1 & `score' != .

tempvar y_demean
sum $Y
gen double `y_demean' = $Y - r(mean)
RDplot `y_demean' `score', z0(-3) z1(1) h(0.1) wid(0.2) degree(0) kernel(gaus) bw($BW) pw($PW) ylab(-0.1(0.05)0.3) xlab(-3(0.5)1 1"1+") ytitle("Log Earnings")
gr export "Results/Main/RDEarnings.png", replace wid(2000) hei(1500)

//Figure 2b
tempvar score
gen double `score' = score_sd 
replace `score' = 1 if `score' >= 1 & `score' != .

tempvar y_res
reghdfe $Y $X $T, absorb(year_area) res(`y_res')
RDplot `y_res' `score', z0(-3) z1(1) h(0.1) wid(0.2) degree(0) kernel(gaus) bw($BW) pw($PW) ylab(-0.1(0.05)0.3) xlab(-3(0.5)1 1"1+") ytitle("Residualized Log Earnings")
gr export "Results/Main/RDEarnings_res.png", replace wid(2000) hei(1500)

/********************************************************************************************
Figure 2: Robustness of the Effect of the National Distinction Award on Early-Career Earnings
*********************************************************************************************/
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009

foreach loc_poly in 1 2 { //Order of Polynomial
	foreach bwmethod in mserd cerrd { //Bandwidth Selection Method
	
	//No controls
	if "`bwmethod'" == "mserd" {
		if `loc_poly' == 1 {
			local action "replace"
		}
		else{
			local action ""    
		}

		rdrobust $Y $running, kernel($kernel) all bwselect(`bwmethod') p(`loc_poly')
		robustplot, spec(nocovs model`loc_poly' bw`bwmethod') save("Results/Main/Data/RDRobust") `action' robust
	}

	//Area x Year FE
	rdrobust $Y $running , $RDoptions bwselect(`bwmethod') p(`loc_poly') covs($S1)
	robustplot, spec(Areayear model`loc_poly' bw`bwmethod') save("Results/Main/Data/RDRobust") robust
	
	//FE + Test Scores
	rdrobust $Y $running , $RDoptions bwselect(`bwmethod') p(`loc_poly') covs($S2)
	robustplot, spec(Areayear scores model`loc_poly' bw`bwmethod') save("Results/Main/Data/RDRobust") robust

	//FE + Test Scores + Individual Characteristics
	rdrobust $Y $running , $RDoptions bwselect(`bwmethod') p(`loc_poly') covs($S3)
	robustplot, spec(Areayear scores covs model`loc_poly' bw`bwmethod') save("Results/Main/Data/RDRobust") robust

	//Field x Year FE
	rdrobust $Y $running , $RDoptions bwselect(`bwmethod') p(`loc_poly') covs($FFE)
	robustplot, spec(Fieldyear model`loc_poly' bw`bwmethod') save("Results/Main/Data/RDRobust") robust

	//FE + Test Scores
	rdrobust $Y $running , $RDoptions bwselect(`bwmethod') p(`loc_poly') covs($FFE $T)
	robustplot, spec(Fieldyear scores model`loc_poly' bw`bwmethod') save("Results/Main/Data/RDRobust") robust

	//FE + Test Scores + Individual Characteristics
	rdrobust $Y $running , $RDoptions bwselect(`bwmethod') p(`loc_poly') covs($FFE $T $X)
	robustplot, spec(Fieldyear scores covs model`loc_poly' bw`bwmethod') save("Results/Main/Data/RDRobust") robust
	
	}
}

/*******************************************************************************
Figure 3: Heterogeneous Effects of the National Distinction Award
********************************************************************************/    
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009

mat RDhet = J(6, 4, .)
matrix colnames RDhet = "Coeff" "SE" "Variable" "Order"

//Parents' Education
rdrobust $Y $running if parents_cllg == 0, $RDoptions bwselect(mserd) p(1) covs($S2 top5 top20)
mat RDhet[1, 1] = e(tau_bc)
mat RDhet[1, 2] = e(se_tau_rb)
mat RDhet[1, 3] = 1
mat RDhet[1, 4] = 1

rdrobust $Y $running if parents_cllg == 1, $RDoptions bwselect(mserd) p(1) covs($S2 top5 top20)
mat RDhet[2, 1] = e(tau_bc)
mat RDhet[2, 2] = e(se_tau_rb)
mat RDhet[2, 3] = 1
mat RDhet[2, 4] = 2

//Network
rdrobust $Y $running if high_network == 0, $RDoptions bwselect(mserd) p(1) covs($S2 top5 top20)
mat RDhet[3, 1] = e(tau_bc)
mat RDhet[3, 2] = e(se_tau_rb)
mat RDhet[3, 3] = 3
mat RDhet[3, 4] = 7

rdrobust $Y $running if high_network == 1, $RDoptions bwselect(mserd) p(1) covs($S2 top5 top20)	
mat RDhet[4, 1] = e(tau_bc)
mat RDhet[4, 2] = e(se_tau_rb)
mat RDhet[4, 3] = 3
mat RDhet[4, 4] = 8

//Gender
rdrobust $Y $running if female == 1, $RDoptions bwselect(mserd) p(1) covs($S2 top5 top20)		
mat RDhet[5, 1] = e(tau_bc)
mat RDhet[5, 2] = e(se_tau_rb)
mat RDhet[5, 3] = 4
mat RDhet[5, 4] = 10

rdrobust $Y $running if female == 0, $RDoptions bwselect(mserd) p(1) covs($S2 top5 top20)
mat RDhet[6, 1] = e(tau_bc)
mat RDhet[6, 2] = e(se_tau_rb)
mat RDhet[6, 3] = 4
mat RDhet[6, 4] = 11

preserve
clear
svmat RDhet, names(col)
gen low95 = Coeff - abs(invnormal(0.025))*SE
gen up95 = Coeff + abs(invnormal(0.025))*SE
save "Results/Main/Data/RDHeterogeneity_cllg_rep_discrete.dta", replace
restore 

/*******************************************************************************
Figure 4: Persistence of the Effect on First τ Observed Earnings
********************************************************************************/  
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009

local T = 5
mat RDt = J(`T', 5, .)
matrix colnames RDt = "t" "RD_balanced" "SE_balanced" "RD_unbalanced" "SE_unbalanced"
local i = 1
foreach t of numlist 1(1)`T'{
	
	mat RDt[`i', 1] = `t'
	
	//Balanced Sample
	rdrobust ln_earningsMW_tau`t' $running if dynmc_sample == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
	mat RDt[`i', 2] = e(tau_bc)
	mat RDt[`i', 3] = e(se_tau_rb)
	
	//Unbalanced Sample
	rdrobust ln_earningsMW_tau`t' $running, $RDoptions bwselect(mserd) p(1) covs($S3)
	mat RDt[`i', 4] = e(tau_bc)
	mat RDt[`i', 5] = e(se_tau_rb)
	
local i = `i' + 1
}

preserve
clear 
svmat RDt, names(col)
save "Results/Main/Data/RDDynamic_3.dta", replace
restore	

/******************************************************************************
Tables
******************************************************************************/

/*******************************************************************************
Table 1: Effect of National Distinction Award on Early-Career Earnings
********************************************************************************/  
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009

rdrobust $Y $running , $RDoptions h($MSE_Bw) b($MSE_Bias) p(1) covs($S1)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
outreg2 using "Results/Main/Data/RDMain.txt", dec(3) bra lab replace dta nonotes ///
adds("Bandwidth", $MSE_Bw, "Control Obs.", Nl, "Treatment Obs.", Nr) ///
addtext("Area x Year FE", "Yes", "Field x Year FE", "No", "Test Scores", "No", "Covariates", "No") 

rdrobust $Y $running , $RDoptions h($MSE_Bw) b($MSE_Bias) p(1) covs($S2)
outreg2 using "Results/Main/Data/RDMain.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $MSE_Bw, "Control Obs.", Nl, "Treatment Obs.", Nr) ///
addtext("Area x Year FE", "Yes", "Field x Year FE", "No", "Test Scores", "Yes", "Covariates", "No") 

rdrobust $Y $running , $RDoptions h($MSE_Bw) b($MSE_Bias) p(1) covs($S3)
outreg2 using "Results/Main/Data/RDMain.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $MSE_Bw, "Control Obs.", Nl, "Treatment Obs.", Nr) ///
addtext("Area x Year FE", "Yes", "Field x Year FE", "No", "Test Scores", "Yes", "Covariates", "Yes") 

//Field x Year FE
rdrobust $Y $running , $RDoptions h($MSE_Bw) b($MSE_Bias) p(1) covs($FFE)
outreg2 using "Results/Main/Data/RDMain.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $MSE_Bw, "Control Obs.", Nl, "Treatment Obs.", Nr) ///
addtext("Area x Year FE", "No", "Field x Year FE", "Yes", "Test Scores", "No", "Covariates", "No") 

rdrobust $Y $running , $RDoptions h($MSE_Bw) b($MSE_Bias) p(1) covs($FFE $T)
outreg2 using "Results/Main/Data/RDMain.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $MSE_Bw, "Control Obs.", Nl, "Treatment Obs.", Nr) ///
addtext("Area x Year FE", "No", "Field x Year FE", "Yes", "Test Scores", "Yes", "Covariates", "No") 

rdrobust $Y $running , $RDoptions h($MSE_Bw) b($MSE_Bias) p(1) covs($FFE $T $X)
outreg2 using "Results/Main/Data/RDMain.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $MSE_Bw, "Control Obs.", Nl, "Treatment Obs.", Nr) ///
addtext("Area x Year FE", "No", "Field x Year FE", "Yes", "Test Scores", "Yes", "Covariates", "Yes") 

/*******************************************************************************
Table 2: National Distinction Award and College Reputation
********************************************************************************/
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009

//Full Sample
rdrobust $Y $running, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if award == 0 & abs($running) <= $Bw
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/CollegeReputation.txt", dec(3) bra dta lab replace nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)  ///
cti("Top 5") //addtext("Model", "RD") 

//Top 5 Colleges
rdrobust $Y $running if top5 == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if award == 0 & abs($running) <= $Bw & top5 == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/CollegeReputation.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)  ///
cti("Top 5") //addtext("Model", "RD") 

//Top 6-20 Colleges
rdrobust $Y $running if top20 == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if award == 0 & abs($running) <= $Bw & top20 == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/CollegeReputation.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)  ///
cti("Top 6-20") //addtext("Model", "RD")

//Low-ranked Colleges
rdrobust $Y $running if above20 == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if award == 0 & abs($running) <= $Bw & above20 == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/CollegeReputation.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)  ///
cti("Above 20") //addtext("Model", "RD")
	
//Wage Gap:
//Middle-ranked Colleges
local sample_top20 ((top20 == 1 & $running >= 0) | (top5 == 1 & $running < 0))
rdrobust $Y $running if `sample_top20', $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if award == 0 & abs($running) <= $Bw & `sample_top20'
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/CollegeReputation.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)  ///
cti("Top 6-20") //addtext("Model", "RD")

//Low-ranked Colleges
local sample_above20 ((above20 == 1 & $running >= 0) | (top5 == 1 & $running < 0))	
rdrobust $Y $running if `sample_above20', $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if award == 0 & abs($running) <= $Bw & `sample_above20'
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/CollegeReputation.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)  ///
cti("Above 20") //addtext("Model", "RD") sortvar(reputation)

/*******************************************************************************
Table 3: Effects on the Allocation of Skills
********************************************************************************/
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009 & $Y != .

rdrobust CIIUMatch2_fst $running, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum CIIUMatch2_fst if award == 0 & abs($running) <= $Bw
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/FieldIndustry.txt", dec(3) bra dta lab replace nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

rdrobust CIIUMatch2_fst $running if top5 == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum CIIUMatch2_fst if award == 0 & abs($running) <= $Bw & top5 == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/FieldIndustry.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

rdrobust CIIUMatch2_fst $running if top20 == 1, $RDoptions bwselect(mserd) p(1) covs($S3)	
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum CIIUMatch2_fst if award == 0 & abs($running) <= $Bw & top20 == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/FieldIndustry.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

rdrobust CIIUMatch2_fst $running if above20 == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum CIIUMatch2_fst if award == 0 & abs($running) <= $Bw & above20 == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/FieldIndustry.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

rdrobust $Y $running if transferable == 0, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if award == 0 & abs($running) <= $Bw & transferable == 0
scalar Mu = r(mean)
outreg2 using "Results/Main/Data/FieldIndustry.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

rdrobust $Y $running if transferable == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if award == 0 & abs($running) <= $Bw & transferable == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/FieldIndustry.txt", dec(3) bra dta lab append nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

/*******************************************************************************
Table 4: Effect of Generic Skills Distinctions on Early-Career Earnings
********************************************************************************/
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year == 2010 & sample == 1

keep $Y running_* yeararea_* $X reading writing sb11score consecutivo top5 top20 above20 yeararea
reshape long running_, i(consecutivo) j(test) string
tab test, gen(d_test)

//All
rdrobust $Y running, all kernel(epanechnikov) vce(cluster yeararea) bwselect(mserd) p(1) covs($X yeararea_* reading writing sb11score d_test*) 
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if running >= -$Bw & running < 0
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/GeneralSkills.txt", dec(3) bra lab replace dta nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)
//Top5
rdrobust $Y running if top5 == 1, all kernel(epanechnikov) vce(cluster yeararea) bwselect(mserd) p(1) covs($X yeararea_* reading writing sb11score d_test*) 
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if running >= -$Bw & running < 0 & top5 == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/GeneralSkills.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)
//Top20
rdrobust $Y running if top20 == 1, all kernel(epanechnikov) vce(cluster yeararea) bwselect(mserd) p(1) covs($X yeararea_* reading writing sb11score d_test*) 
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if running >= -$Bw & running < 0 & top20 == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/GeneralSkills.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)
//Below20
rdrobust $Y running if above20 == 1, all kernel(epanechnikov) vce(cluster yeararea) bwselect(mserd) p(1) covs($X yeararea_* reading writing sb11score d_test*)  
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum $Y if running >= -$Bw & running < 0 & above20 == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/GeneralSkills.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

/*******************************************************************************
Table 5: Effects on Additional Accumulation of Skills
********************************************************************************/
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009 & $Y != .

foreach rep of varlist sample top5 top20 above20{

rdrobust months_exam_to_grad $running if `rep' == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum months_exam_to_grad if award == 0 & abs($running) <= $Bw & `rep' == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/HumanCapital_`rep'.txt", dec(3) bra lab replace dta nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

rdrobust tot_classtaken $running if `rep' == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum tot_classtaken if award == 0 & abs($running) <= $Bw & `rep' == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/HumanCapital_`rep'.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

rdrobust classtaken_aftexam $running if `rep' == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum classtaken_aftexam if award == 0 & abs($running) <= $Bw & `rep' == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/HumanCapital_`rep'.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

rdrobust classpass_aftexam $running if `rep' == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum classpass_aftexam if award == 0 & abs($running) <= $Bw & `rep' == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/HumanCapital_`rep'.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

rdrobust gradsch $running if `rep' == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
global Bw = e(h_l)
scalar Nl = e(N_h_l)
scalar Nr = e(N_h_r)
sum gradsch if award == 0 & abs($running) <= $Bw & `rep' == 1
scalar Mu = r(mean) 
outreg2 using "Results/Main/Data/HumanCapital_`rep'.txt", dec(3) bra lab append dta nonotes ///
adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)
	
}

/*******************************************************************************************
Table 6: Effects on the Probability of Switching Jobs and Job Characteristics After Switching
********************************************************************************************/
use "Data/Finals/Estimation Sample.dta", clear
keep if exam_year <= 2009 & $Y != .

foreach school of varlist sample top5 top20 above20 {
	
	rdrobust $Y $running if `school' == 1, $RDoptions bwselect(mserd) p(1) covs($S3)
	global Bw = e(h_l)
	global Bias = e(b_l)
	
	rdrobust ln_earningsMW_tau1 $running if `school' == 1, $RDoptions h($Bw) b($Bias) p(1) covs($S3)
	scalar Nl = e(N_h_l)
	scalar Nr = e(N_h_r)
	sum ln_earningsMW_tau1 if award == 0 & abs($running) <= $Bw & `school' == 1
	scalar Mu = r(mean)
	outreg2 using "Results/Main/Data/Job-Ladder_P1_`school'_CIIU_3.txt", dec(3) bra lab replace dta nonotes ///
	adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)	
	
	rdrobust ln_earningsMW_tau2 $running if `school' == 1, $RDoptions h($Bw) b($Bias) p(1) covs($S3)
	scalar Nl = e(N_h_l)
	scalar Nr = e(N_h_r)
	sum ln_earningsMW_tau2 if award == 0 & abs($running) <= $Bw & `school' == 1
	scalar Mu = r(mean)
	outreg2 using "Results/Main/Data/Job-Ladder_P1_`school'_CIIU_3.txt", dec(3) bra lab append dta nonotes ///
	adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)	
	
	rdrobust ln_earningsMW_tau3 $running if `school' == 1, $RDoptions h($Bw) b($Bias) p(1) covs($S3)
	scalar Nl = e(N_h_l)
	scalar Nr = e(N_h_r)
	sum ln_earningsMW_tau3 if award == 0 & abs($running) <= $Bw & `school' == 1
	scalar Mu = r(mean)
	outreg2 using "Results/Main/Data/Job-Ladder_P1_`school'_CIIU_3.txt", dec(3) bra lab append dta nonotes ///
	adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)
	
	cap drop mover
	gen mover = 1 if ((CIIURank_tau1 != CIIURank_tau2) & CIIURank_tau1 != . & CIIURank_tau2 != .) | ((CIIURank_tau2 != CIIURank_tau3) & CIIURank_tau2 != . & CIIURank_tau3 != .) & `school' == 1
	replace mover = 0 if mover == . & ((CIIURank_tau1 != . & CIIURank_tau2 != .) | (CIIURank_tau2 != . & CIIURank_tau3 != .))  & `school' == 1
	rdrobust mover $running if `school' == 1, $RDoptions h($Bw) b($Bias) p(1) covs($S3) 
	scalar Nl = e(N_h_l)
	scalar Nr = e(N_h_r)
	sum mover if award == 0 & abs($running) <= $Bw & `school' == 1
	scalar Mu = r(mean)
	outreg2 using "Results/Main/Data/Job-Ladder_P1_`school'_CIIU_3.txt", dec(3) bra lab append dta nonotes ///
	adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

	rdrobust CIIURank_tau1 $running if `school' == 1, $RDoptions h($Bw) b($Bias) p(1) covs($S3)
	scalar Nl = e(N_h_l)
	scalar Nr = e(N_h_r)
	sum CIIURank_tau1 if award == 0 & abs($running) <= $Bw & `school' == 1
	scalar Mu = r(mean)
	outreg2 using "Results/Main/Data/Job-Ladder_P1_`school'_CIIU_3.txt", dec(3) bra lab append dta nonotes ///
	adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)
	
	local sample CIIURank_tau2 != . 
	rdrobust CIIURank_delta12 $running if `sample' & `school' == 1, $RDoptions h($Bw) b($Bias) p(1) covs($S3)
	scalar Nl = e(N_h_l)
	scalar Nr = e(N_h_r)
	sum CIIURank_delta12 if award == 0 & abs($running) <= $Bw & `sample' & `school' == 1
	scalar Mu = r(mean)
	outreg2 using "Results/Main/Data/Job-Ladder_P1_`school'_CIIU_3.txt", dec(3) bra lab append dta nonotes ///
	adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)

	local sample CIIURank_tau3 != . 
	rdrobust CIIURank_delta13 $running if `sample' & `school' == 1, $RDoptions h($Bw) b($Bias) p(1) covs($S3)
	scalar Nl = e(N_h_l)
	scalar Nr = e(N_h_r)
	sum CIIURank_delta13 if award == 0 & abs($running) <= $Bw & `sample' & `school' == 1
	scalar Mu = r(mean)
	outreg2 using "Results/Main/Data/Job-Ladder_P1_`school'_CIIU_3.txt", dec(3) bra lab append dta nonotes ///
	adds("Bandwidth", $Bw, "Control Obs.", Nl, "Treatment Obs.", Nr, "Mean Control", Mu)	

}
